package com.baymax.study.base.beanLifeCycle;

import lombok.Data;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * MyUserBean
 *
 * @author Baymax
 * @since 2024-03-23
 */
@Data
@Component
public class MyUserBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String beanName;

    private BeanFactory beanFactory;

    private ApplicationContext applicationContext;

    public MyUserBean() {
        System.out.println("[02]实例化: 构造器");
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("-回调接口: BeanNameAware#setBeanName");
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        System.out.println("-回调接口: BeanFactoryAware#setBeanFactory");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        System.out.println("-回调接口: ApplicationContextAware#setApplicationContext");
        this.applicationContext = applicationContext;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("[08]销毁Bean: DisposableBean#destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("[06]初始化-属性注入完成后: InitializingBean#afterPropertiesSet");
    }
}
